package LeetCodeP;

import java.util.ArrayList;
import java.util.Collections;

/**
 * 1 <= A.length = A[0].length <= 20
 * 0 <= A[i][j] <= 1
 *输入: [[1,1,0],[1,0,1],[0,0,0]]
 * 输出: [[1,0,0],[0,1,0],[1,1,1]]
 *解释: 首先翻转每一行: [[0,1,1],[1,0,1],[0,0,0]]；
 *      然后反转图片: [[1,0,0],[0,1,0],[1,1,1]]
 */
public class Soluction832 {

    public static int[][] flipAndInvertImage3(int [][] A){
        int [][] B=new int[A.length][A.length];
        for (int i=0;i<A.length;i++){
            for (int j=0;j<A.length;j++){
                B[i][j]=A[i][j];
                if (B[i][j]==1){
                    B[i][j]=0;
                }else {
                    B[i][j]=1;
                }
            }
        }
        return B;
    }

    public  static  int[][] flipAndInvertImage(int[][] A) {
        int [][] B=new int[A.length][A.length];
        for (int i=0;i<A.length;i++){
            for (int j=0;j<A.length;j++){
                B[i][j]=A[i][A.length-j-1];
                if (B[i][j]==1){
                    B[i][j]=0;
                }else {
                    B[i][j]=1;
                }
            }
        }
        return B;
    }
    public  static  int[][] flipAndInvertImage2(int[][] A) {
        int [][] B=new int[A.length][A.length];
        ArrayList<Integer> integers = new ArrayList<>();
        for (int i=0;i<A.length;i++){
            for (int j=0;j<A.length;j++){
                integers.add(B[i][j]);
            }
        }
        Collections.reverse(integers);
        return B;
    }

    public static void main(String[] args) {
//      int [][] A={{1,1,0},{1,0,1},{0,0,0}};
        int [][] A={{0,1,1},{1,0,1},{0,0,0}};
        int[][] ints = flipAndInvertImage3(A);
        for (int i = 0; i <ints.length ; i++) {
            for (int j=0;j<ints.length;j++){
                System.out.print(ints[i][j]);
            }
        }

    }
}
